<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title data-i18n="resources.title_themeGridUnique"></title>
    <style type="text/css">
        .editPane {
            position: absolute;
            right: 60px;
            top: 50px;
            text-align: center;
            background: #FFF;
            z-index: 1000;
        }
    </style>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
<div class='panel panel-primary editPane' id='editPane' style="z-index: 99999">
    <div class='panel-heading'>
        <h5 class='panel-title text-center' data-i18n="resources.title_themeGridUnique"></h5>
    </div>
    <div class='panel-body' id='params'>
        <p></p>
        <div align='right' class='button-group'>
            <input type='button' id='btn1' class='btn btn-primary' data-i18n="[value]resources.btn_addThemeLayer" onclick="addThemeGridUnique()"/>
            <input type='button' id='btn2' class='btn btn-primary' data-i18n="[value]resources.text_input_value_clear" onclick="removeTheme()"/>
        </div>
    </div>
</div>
<div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
<script type="text/javascript" include="bootstrap,widgets.alert" src="../js/include-web.js"></script>
<script type="text/javascript" exclude="iclient-classic" src="../../dist/classic/include-classic.js"></script>
<script type="text/javascript">
    var map, baseLayer, themeLayer,
        host = window.isLocal ? window.server : "https://iserver.supermap.io",
        url = host + "/iserver/services/map-jingjin/rest/maps/京津地区土地利用现状图";
    map = new SuperMap.Map("map", {
        controls: [
            new SuperMap.Control.LayerSwitcher(),
            new SuperMap.Control.ScaleLine(),
            new SuperMap.Control.Zoom(),
            new SuperMap.Control.Navigation({
                dragPanOptions: {
                    enableKinetic: true
                }
            })]
    });
    baseLayer = new SuperMap.Layer.TiledDynamicRESTLayer("jingjin", url, {
        transparent: true,
        cacheEnabled: true
    }, {maxResolution: "auto"});
    baseLayer.events.on({"layerInitialized": addLayer});

    function addLayer() {
        map.addLayer(baseLayer);
        map.setCenter(new SuperMap.LonLat(117.2, 40.11), 0);
        map.allOverlays = true;
    }
    function addThemeGridUnique() {
        removeTheme();
        var themeService = new SuperMap.REST.ThemeService(url, {
            eventListeners: {
                "processCompleted": themeCompleted,
                "processFailed": themeFailed
            }
        });
        //定义单值专题图子项
        function setItems() {
            var items = new Array(),
                color0 = new SuperMap.REST.ServerColor(198, 244, 240),
                color1 = new SuperMap.REST.ServerColor(176, 244, 188),
                color2 = new SuperMap.REST.ServerColor(218, 251, 178),
                color3 = new SuperMap.REST.ServerColor(220, 236, 145),
                color4 = new SuperMap.REST.ServerColor(96, 198, 66),
                color5 = new SuperMap.REST.ServerColor(20, 142, 53),
                color6 = new SuperMap.REST.ServerColor(85, 144, 55),
                color7 = new SuperMap.REST.ServerColor(171, 168, 38),
                color8 = new SuperMap.REST.ServerColor(235, 165, 9),
                color9 = new SuperMap.REST.ServerColor(203, 89, 2),
                color10 = new SuperMap.REST.ServerColor(157, 25, 1),
                color11 = new SuperMap.REST.ServerColor(118, 15, 3),
                color12 = new SuperMap.REST.ServerColor(112, 32, 7),
                color13 = new SuperMap.REST.ServerColor(106, 45, 12),
                color14 = new SuperMap.REST.ServerColor(129, 80, 50),
                color15 = new SuperMap.REST.ServerColor(160, 154, 146);

            for (var i = -4; i < 2197; i++) {
                var num = parseInt(i / 135);
                var item = new SuperMap.REST.ThemeGridUniqueItem();
                item.caption = 1;
                item.unique = i;
                item.visible = true;
                switch (num) {
                    case 0:
                        item.color = color0;
                        break;
                    case 1:
                        item.color = color1;
                        break;
                    case 2:
                        item.color = color2;
                        break;
                    case 3:
                        item.color = color3;
                        break;
                    case 4:
                        item.color = color4;
                        break;
                    case 5:
                        item.color = color5;
                        break;
                    case 6:
                        item.color = color6;
                        break;
                    case 7:
                        item.color = color7;
                        break;
                    case 8:
                        item.color = color8;
                        break;
                    case 9:
                        item.color = color9;
                        break;
                    case 10:
                        item.color = color10;
                        break;
                    case 11:
                        item.color = color11;
                        break;
                    case 12:
                        item.color = color12;
                        break;
                    case 13:
                        item.color = color13;
                        break;
                    case 14:
                        item.color = color14;
                        break;
                    case 15:
                        item.color = color15;
                        break;
                    default:
                        item.color = color0;
                        break;
                }
                items.push(item);
            }
            return items;
        }

        var themeGridUnique = new SuperMap.REST.ThemeGridUnique({
            defaultcolor: new SuperMap.REST.ServerColor(0, 0, 0),
            items: setItems()
        });
        themeParameters = new SuperMap.REST.ThemeParameters({
            datasetNames: ["JingjinTerrain"],
            dataSourceNames: ["Jingjin"],
            themes: [themeGridUnique],
            types: ['GRID']
        });

        themeService.processAsync(themeParameters);
    }

    function themeCompleted(themeEventArgs) {
        if (themeEventArgs.result.resourceInfo.id) {
            themeLayer = new SuperMap.Layer.TiledDynamicRESTLayer("jingjin_themeGridUnique", url, {
                cacheEnabled: false,
                transparent: true,
                layersID: themeEventArgs.result.resourceInfo.id
            }, {"maxResolution": "auto"});
            themeLayer.events.on({"layerInitialized": addThemeLayer});
        }
    }
    function addThemeLayer() {
        map.addLayer(themeLayer);
    }

    function themeFailed(serviceFailedEventArgs) {
        widgets.alert.showAlert(serviceFailedEventArgs.error.errorMsg, false);
    }

    function removeTheme() {
        if (map.layers.length > 1) {
            map.removeLayer(themeLayer, true);
        }
    }

</script>
</body>
</html>
